package HLLib.control.HLCheckBox;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLImage;
import HLLib.base.HLInputManager;
import HLLib.base.HLMath;
import HLLib.base.HLString;
import HLLib.control.HLPanel;
import HLLib.http.IEvent;

public class HLCheckBoxImage extends HLPanel {
    String text;

    public static final int border = 0;

    public int responseKeys = GAME_BUTTON_ACTION;

    public Image img0;

    public Image img1;

    public int textColor = 0xff949494;

    public IEvent eventChangeSelect;

    public HLCheckBoxImage(Image img0, Image img1, String text) {
        this.text = text;
        width = (short) (HLGraphics.StringWidth1(text) + 2 + border + img0.getWidth() + 2);
        height = (short) (Math.max(HLGraphics.StringHeight() + border, img0.getHeight()) + 2);
        result = 1;
        this.img0 = img0;
        this.img1 = img1;
    }

    public void Refresh() {

    }

    public void Logic() {
        int screenX = super.GetScreenX();
        int screenY = super.GetScreenY();
        super.Logic();
        // if ()
        {
            if ((IsFocus() && HLInputManager.IsInputDown(responseKeys)) || (HLInputManager.PointDownInRect(screenX, screenY, width, height))) {
                result = (short) (1 - result);
                if (eventChangeSelect != null) {
                    eventChangeSelect.Action(this, null);
                }
            }
        }
    }

    public void Render(HLGraphics g) {
        int ScreenX = super.GetScreenX();
        int ScreenY = super.GetScreenY();

        if (IsFocus()) {
            g.FillRectAlpha(ScreenX, ScreenY, width, height, 0xff448ff8);
            g.DrawStringAdjustable(new HLString(text), 0xffffffff, 0, ScreenX, ScreenY, width - 1, height, TEXT_STYLE_NORMAL, RIGHT_VCENTER);
        } else {
            g.DrawStringAdjustable(new HLString(text), textColor, 0, ScreenX, ScreenY, width - 1, height, TEXT_STYLE_NORMAL, RIGHT_VCENTER);
        }
        int yVCenter = HLMath.GetPosAdjustableV(img1.getHeight(), ScreenY, height, VCENTER);
        if (result == 1) {
            g.DrawImage(new HLImage(img1), ScreenX + 1, yVCenter, TRANS_NONE);
        } else {
            g.DrawImage(new HLImage(img0), ScreenX + 1, yVCenter, TRANS_NONE);
        }
    }

}
